//
//  EmoticonPackages.m
//  WLEmotionKeyBoard
//
//  Created by wanglei on 16/12/8.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "EmoticonPackages.h"

@implementation EmoticonPackages

/*
 每隔20个按钮需要一个删除按钮 --> 就是添加删除按钮的数据源
 页面表情不足21个需要补足空表情
 */

- (id)initWithid:(NSString *)id name:(NSString *)name array:(NSArray *)array;{
    self = [super init];
    
    if(self){
        self.group_name_cn = name;
        self.emoticons = array;
        NSInteger index = 0;
        NSMutableArray <Emoticon *>*mutArray= [[NSMutableArray alloc]init];
        for (Emoticon *item in array){
            Emoticon *e = [[Emoticon alloc]initWithid:id dict:item];
            [mutArray addObject:e];
            NSLog(@"mutArray= %@",mutArray);
            index ++;
            if(index == 20){
//                添加删除按钮
                Emoticon *delete = [[Emoticon alloc]initWithisDelete:YES];
                [mutArray addObject:delete];
                index = 0;
            }
        }
        self.emoticonList = mutArray;
        NSLog(@"self.emoticonList = %@",self.emoticonList);
//        添加完删除按钮需判断页面表情不足21个需补齐空表情
        [self addEmptyEmoticon];
    }
    return self;
}

- (void)addEmptyEmoticon{
    NSInteger detla = self.emoticonList.count % 21;
    if(detla == 0){
        return;
    }
    Emoticon *empty = [[Emoticon alloc]initWithisEmpty:true];
    for(NSInteger i = detla;i < 20;i ++){
        //                添加删除按钮
        [self.emoticonList addObject:empty];
    }
    
//    最后一个添加删除表情
    Emoticon *delete = [[Emoticon alloc]initWithisDelete:true];
    [self.emoticonList addObject:delete];
}
@end
